function Table5

addpath('../Data')
addpath('basic_functions')

Nfactors = 3;
Nboot = 1000;

[Return,Z,IsF,Nt,Chars,CharsNames,~,~,~] = package_data_all_greeks;
Return = Return.ret_daily;
[N,T,L] = size(Z);

% construct W and X matrices that will be used for IPCA
W = NaN(L,L,T);
X = NaN(L,T);
for t = 1:T-1
    W(:,:,t) = squeeze(Z(IsF(:,t+1),t,:))'*squeeze(Z(IsF(:,t+1),t,:)) / Nt(t+1);
    X(:,t+1) = squeeze(Z(IsF(:,t+1),t,:))'*Return(IsF(:,t+1),t+1) / Nt(t+1);
    Return(~IsF(:,t+1),t+1) = NaN;
end
clear t

[G, F] = IPCA(X,W,Nt,Nfactors);
%R2 = IPCA_R2(G,F,Return,Z,IsF,X,W);

sqG2 = sqrt(sum(G.^2,2));
pval = NaN(L-1,1);
for ell = 1:L-1
    pval(ell) = IPCA_char_pvalues(X,W,Nt,G,F,ell,Nboot);
end
[X,ia] = sortrows([sqG2(1:end-1) pval'],-1);

bh = BH(pval',0.05);
for ell = 1:size(X,1)/2
    bb = ['&' num2str(X(ell,1),'%1.2f') '&' num2str(X(ell,2),'%1.2f')];
    cc = ['&' num2str(X(size(X,1)/2+ell,1),'%1.2f') '&' num2str(X(size(X,1)/2+ell,2),'%1.2f')];
    disp([CharsNames{ia(ell),1} bb '&&' CharsNames{ia(size(X,1)/2+ell),1} cc '\\'])
end

return